# -*- coding: utf-8 -*-
import requests
import re
import json


url = "https://desk.zol.com.cn/bizhi/9297_113585_2.html"
headers= {
    'user-agent': 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Mobile Safari/537.36',
    'referer':url
}
res = requests.get(url,headers = headers)
obj = re.compile(r"var deskPicArr.*?=(?P<deskPicArr>.*?);",re.S)
result = obj.search(res.text)
deskPicStr = result.group("deskPicArr")
deskPic = json.loads(deskPicStr)

for item in deskPic['list']:
    oriSize = item.get("oriSize")
    imgsrc = item.get("imgsrc")
    imgsrc = imgsrc.replace("##SIZE##",oriSize) #字符串替换

    name = imgsrc.split("/")[-1]#获取图片名称
    #print(name,imgsrc)
    resp_img = requests.get(imgsrc,headers = headers) #发送网络请求
    #下载
    with open("img/"+name, mode="wb") as f:
        f.write(resp_img.content)

#多线程
# 1导包 from threading import Thread
# 2创建任务 def func().....
# 3创建线程 t = Thread(target=func, args=("name",))
# 4启动线程 t.start()

#线程池
# from concurrent.futures import ThreadPoolExecutor
# 创建线程池
# with ThreadPoolExecutor(20) as t:
#      t.submit(func,"周杰伦参数")
